package org.jeecg.modules.friends.dao.impl;

import java.util.List;

import org.jeecg.modules.friends.condition.UserReportCondition;
import org.jeecg.modules.friends.condition.VipUserCondition;
import org.jeecg.modules.friends.dao.UserReportDAO;
import org.jeecg.modules.friends.mapper.ext.UserReportDOExtMapper;
import org.jeecg.modules.friends.model.UserReportDO;
import org.jeecg.modules.friends.model.VipUserDO;
import org.jeecg.modules.friends.user.param.UserReportHandleParam;
import org.jeecg.modules.friends.user.param.UserReportParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserReportDAOImpl implements org.jeecg.modules.friends.dao.UserReportDAO {
    @Autowired
    private UserReportDOExtMapper userReportDOExtMapper;


    @Override
    public void insert(UserReportDO userReportDO) {
        userReportDOExtMapper.insert(userReportDO);
    }

    @Override
    public void deleteByCondition(Long userId) {
        UserReportCondition condition = new UserReportCondition();
        UserReportCondition.Criteria criteria = condition.createCriteria();
        criteria.andFromUserIdEqualTo(userId);
        userReportDOExtMapper.deleteByCondition(condition);
    }

    @Override
    public List<UserReportDO> selectUserReportPage(int page, int pageSize, Long userId, UserReportParam param) {
        UserReportCondition userReportCondition = new UserReportCondition();
        userReportCondition.setOffset((page - 1) * pageSize);
        userReportCondition.setLimit(pageSize);
        UserReportCondition.Criteria criteria = userReportCondition.createCriteria();
        if (userId != null && userId > 0) {
            criteria.andToUserIdEqualTo(userId);
        }
        if (param.getHandleTag() != null) {
            criteria.andStatusEqualTo(param.getHandleTag());
        }
        return userReportDOExtMapper.selectByCondition(userReportCondition);
    }

    @Override
    public void update(UserReportHandleParam param) {
        if (param.getId() == null || param.getHandleTag() == null) {
            return;
        }
        UserReportDO paramContent = new UserReportDO();
        paramContent.setId(param.getId());
        paramContent.setStatus(param.getHandleTag());
        userReportDOExtMapper.updateByPrimaryKeySelective(paramContent);
    }

    @Override
    public long countUserReportPage(int page, int pageSize, Long userId, UserReportParam param) {
        UserReportCondition userReportCondition = new UserReportCondition();
        userReportCondition.setOffset((page - 1) * pageSize);
        userReportCondition.setLimit(pageSize);

        UserReportCondition.Criteria criteria = userReportCondition.createCriteria();
        if (userId != null && userId > 0) {
            criteria.andToUserIdEqualTo(userId);
        }
        if (param.getHandleTag() != null) {
            criteria.andStatusEqualTo(param.getHandleTag());
        }
        return userReportDOExtMapper.countByCondition(userReportCondition);
    }
}
